/* 
 * @description: 文本相关组件
 * @author: Jane 
 * @date: 2023-09-12 17:25:30
 */

import 'package:basic_common/app_theme.dart';
import 'package:basic_common/screen_helper.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:roundcheckbox/roundcheckbox.dart';

/// 平台协议 隐私政策
Widget agreementWidget(bool isRead, {required void Function(bool?)? onChange}) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.start,
    children: [
      Container(
        width: ScreenHelper.width(260),
        child: ListTile(
          dense: true,
          contentPadding: EdgeInsets.zero,
          minLeadingWidth: ScreenHelper.width(2),
          leading: Container(
            child: RoundCheckBox(
                size: ScreenHelper.width(16), //checkBox大小
                checkedWidget: Icon(
                  Icons.check,
                  color: Colors.white,
                  size: ScreenHelper.width(14),
                ),
                checkedColor: AppTheme.primyColor,
                uncheckedColor: Colors.white,
                border: Border.all(color: AppTheme.primyColor, width: 1),
                isChecked: isRead,
                onTap: onChange),
          ),
          title: Container(
            height: ScreenHelper.height(16),
            alignment: Alignment.centerLeft,
            child: Text.rich(
              TextSpan(
                  style: TextStyle(
                    fontSize: ScreenHelper.sp(12),
                    color: AppTheme.weakTextColor,
                  ),
                  children: [
                    const TextSpan(
                        text: "我已阅读并同意",
                        style: TextStyle(color: AppTheme.dartWeakTextColor)),
                    textLink("《用户隐私协议》", type: 1),
                  ]),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ),
    ],
  );
}

/// 跳转Webview富文本
/// title 文字内容
/// url 跳转链接
TextSpan textLink(String title,
    {required int type, String url = '', Function()? onTap}) {
  return TextSpan(
    text: title,
    style: TextStyle(color: AppTheme.primyColor, fontSize: ScreenHelper.sp(13)),
    recognizer: TapGestureRecognizer()..onTap = onTap,
  );
}

/// 小标题样式
/// isBlod 是否加粗
Widget norTitle(
    {required String title,
    bool isBlod = false,
    AlignmentGeometry? alignment = Alignment.topLeft,
    double top = 10,
    double bottom = 15}) {
  return Container(
    alignment: Alignment.topLeft,
    margin: EdgeInsets.only(
        top: ScreenHelper.height(top), bottom: ScreenHelper.height(bottom)),
    child: Text(
      title,
      style: TextStyle(
          color: AppTheme.dartTextColor,
          fontSize: ScreenHelper.sp(16),
          fontWeight: isBlod ? FontWeight.bold : FontWeight.normal),
      textAlign: TextAlign.left,
    ),
  );
}

/// 空数据

Widget EmptyBox({required String title}) {
  return Column(
    mainAxisAlignment: MainAxisAlignment.start,
    children: [
      SizedBox(
        height: ScreenHelper.height(20),
      ),
      Image.asset(
        "assets/empty.png",
        width: ScreenHelper.width(200),
        package: "basic_common",
      ),
      SizedBox(
        height: ScreenHelper.height(10),
      ),
      Text(
        title,
        style: TextStyle(color: AppTheme.weakTextColor),
      )
    ],
  );
}

///上下文字模板
Widget textAndSub(
    {required String title,
    required String subTitle,
    Color subTextColor = AppTheme.seconddarkWeakTextColor,
    double titleFontSize = 16}) {
  return Column(
    children: [
      Text(
        title,
        style: TextStyle(
            color: AppTheme.dartTextColor,
            fontSize: ScreenHelper.sp(titleFontSize)),
        textAlign: TextAlign.center,
      ),
      SizedBox(
        height: ScreenHelper.height(10),
      ),
      Text(
        subTitle,
        style: TextStyle(color: subTextColor, fontSize: ScreenHelper.sp(14)),
        textAlign: TextAlign.center,
      ),
    ],
  );
}

/// 顶部黄色提示
Widget topTipWidget(
    {String title = "平台严格保障您的信息安全,请放心填写", bool isComplete = false}) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.start,
    children: [
      Expanded(
        child: Container(
          padding: EdgeInsets.all(ScreenHelper.width(12)),
          decoration: BoxDecoration(
              color: isComplete
                  ? AppTheme.primyColor.withOpacity(.2)
                  : Color.fromRGBO(255, 249, 242, 1)),
          child: Text(
            title,
            style: TextStyle(
              color: isComplete ? AppTheme.primyColor : AppTheme.tipTextColor,
              fontSize: ScreenHelper.sp(14),
            ),
          ),
        ),
      ),
    ],
  );
}

/// 文本属性名称
Widget textItemWidget(
    {required String attrName,
    required String value,
    double fontSize = 14,
    double width = 90,
    Color valuColor = AppTheme.seconddarkWeakTextColor}) {
  TextStyle textStyle = TextStyle(
      color: AppTheme.seconddarkWeakTextColor,
      fontSize: ScreenHelper.sp(fontSize));
  TextStyle subStyle =
      TextStyle(color: valuColor, fontSize: ScreenHelper.sp(fontSize));
  return Container(
    margin: EdgeInsets.symmetric(vertical: ScreenHelper.height(4)),
    child: Row(
      children: [
        SizedBox(
          width: ScreenHelper.width(width),
          child: Text(
            attrName,
            style: textStyle,
          ),
        ),
        SizedBox(
          width: ScreenHelper.width(10),
        ),
        Text(
          value,
          style: subStyle,
        ),
      ],
    ),
  );
}


/// Divier
Widget divider() {
  return const Divider(
    height: 1,
    color: AppTheme.dividerColor,
  );
}


